// pages/lb/lb.js
import {request} from '../../request/index'
Page({

    /**
     * 页面的初始数据
     */
    data: {
        tabs:[
            {
                id:0,
                value:"综合",
                isActive:true,
            },
            {
                id:1,
                value:"销量",
                isActive:false,
            },
            {
                id:2,
                value:"价格",
                isActive:false,
            },
        ],
        goodsList:[

        ]
    },
        QueryParams:{
            query:"",
            cid:"",
            pagenum:1,
            pagesize:10,
        },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
       this.QueryParams.cid=options.cid;
       this.getGoodsList();
    },
    // 获取商品列表的数据
    async getGoodsList(){
        const res=await request({url:'https://api-hmugo-web.itheima.net/api/public/v1/goods/search',data:this.QueryParams});
        this.setData({
            goodsList:res.goods
        })
    },
    // 标题的点击事件
    handelTabsItemChange(e){
        console.log(e);
        const {index}=e.detail;
        let {tabs}=this.data;
        tabs.forEach((v,i)=>i===index?v.isActive=true:v.isActive=false);
        this.setData({
            tabs
        })
    }
})

